﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Root.master" AutoEventWireup="true" CodeFile="Request.aspx.cs" Inherits="Default2" %>

<%@ Register assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxFormLayout" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="Server">

    <script type="text/javascript">
        function OnJobChanged() {
            cbb_JobSubType.PerformCallback(cbLocation.GetText());

        }
    </script>
    <dx:ASPxFormLayout ID="ASPxFormLayout1" runat="server">
        <Items>
            <dx:LayoutGroup Caption="Layout Group" ColCount="2" HorizontalAlign="Left" RowSpan="2" ShowCaption="False">
                <Items>
                    <dx:LayoutItem Caption="Дата подачи заявки: с" ShowCaption="True">
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                <dx:ASPxDateEdit ID="dt1" runat="server" ClientInstanceName="dt1">
                                    <ValidationSettings>
                                        <RequiredField IsRequired="True" />
                                    </ValidationSettings>
                                </dx:ASPxDateEdit>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                    <dx:LayoutItem Caption="по">
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                <dx:ASPxDateEdit ID="dt2" runat="server" ClientInstanceName="dt2">
                                    <ValidationSettings>
                                        <RequiredField IsRequired="True" />
                                    </ValidationSettings>
                                </dx:ASPxDateEdit>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                </Items>
                <SettingsItems HorizontalAlign="Left" />
            </dx:LayoutGroup>
            <dx:LayoutGroup Caption="Layout Group" ColCount="2" HorizontalAlign="Left" ShowCaption="False">
                <Items>
                    <dx:LayoutGroup Caption="Layout Group" ShowCaption="False">
                        <Items>
                            <dx:LayoutItem Caption="Вид работ:">
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="JobTypeID" runat="server" Width="100%" DataSourceID="ds_JobType" TextField="Title" ValueField="JobTypeId">
                                            <ClientSideEvents SelectedIndexChanged="function(s, e) { cbb_JobSubType.PerformCallback(s.GetValue()); }" />
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="Подвид работ:">
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="JobTypeSubID" runat="server" Width="100%" OnCallback="JobTypeSubID_Callback" DataSourceID="ds_JobSubtype" ClientInstanceName="cbb_JobSubType" TextField="Title" ValueField="JobSubtypeId">
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="Локализация:">
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="LocationID" runat="server" Width="100%" SelectedIndex="0">
                                            <Items>
                                                <dx:ListEditItem Selected="True" Text="[Все]" Value="-1" />
                                                <dx:ListEditItem Text="Дом" Value="1" />
                                                <dx:ListEditItem Text="Квартира" Value="2" />
                                                <dx:ListEditItem Text="Подъезд" Value="3" />
                                                <dx:ListEditItem Text="Лестничная клетка" Value="4" />
                                                <dx:ListEditItem Text="Крыша" Value="5" />
                                                <dx:ListEditItem Text="Другое" Value="6" />
                                                <dx:ListEditItem Text="Подвал" Value="7" />
                                                <dx:ListEditItem Text="Мусоропровод" Value="8" />
                                                <dx:ListEditItem Text="Территория" Value="9" />
                                                <dx:ListEditItem Text="Карман" Value="10" />
                                            </Items>
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="Состояние:">
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="StatusID" runat="server" Width="100%" SelectedIndex="0">
                                            <Items>
                                                <dx:ListEditItem Text="[Все]" Value="-1" Selected="True" />
                                                <dx:ListEditItem Text="Не рассмотрена" Value="1" />
                                                <dx:ListEditItem Text="В процессе" Value="2" />
                                                <dx:ListEditItem Text="Выполнена" Value="3" />
                                                <dx:ListEditItem Text="Возвращена" Value="4" />
                                                <dx:ListEditItem Text="Снята" Value="5" />
                                                <dx:ListEditItem Text="Закрыта" Value="6" />
                                                <dx:ListEditItem Text="Отложена" Value="7" />
                                                <dx:ListEditItem Text="Текущий ремонт" Value="8" />
                                                <dx:ListEditItem Text="Запрос в СЭ" Value="9" />
                                            </Items>
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                        </Items>
                    </dx:LayoutGroup>
                    <dx:LayoutGroup Caption="Layout Group" ShowCaption="False">
                        <Items>
                            <dx:LayoutItem Caption="Улица:">
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="cbb_Street" runat="server" Width="100%" DataSourceID="ds_street" TextField="Title" ValueField="StreetId"
                                            ValueType="System.Int32" IncrementalFilteringMode="StartsWith" EnableCallbackMode="true" CallbackPageSize="30">
                                            <ClientSideEvents SelectedIndexChanged="function(s, e) { cbb_House.PerformCallback(s.GetValue()); }" />
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="Дом:">
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="houseID" runat="server" ClientInstanceName="cbb_House" Width="100%" DataSourceID="ds_house" 
                                            OnCallback="houseID_Callback" TextField="Title" ValueField="HouseId" ValueType="System.Int32"
                                            IncrementalFilteringMode="StartsWith" EnableCallbackMode="true" CallbackPageSize="30">
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="Квартира:">
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxTextBox ID="flatID" runat="server" Width="100%">
                                        </dx:ASPxTextBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                        </Items>
                    </dx:LayoutGroup>
                </Items>
                <SettingsItems HorizontalAlign="Left" />
            </dx:LayoutGroup>
        </Items>
    </dx:ASPxFormLayout>
    <table style="margin-left: 10px">
        <tr>
            <td>
                <dx:ASPxButton ID="ASPxButton1" runat="server" Text="Найти" Width="80px" OnClick="btn_find_Click" AutoPostBack="False" UseSubmitBehavior="False">
                </dx:ASPxButton>
            </td>
            <td>
                <dx:ASPxButton ID="ASPxButton2" runat="server" Text="Очистить" Width="80px" OnClick="ASPxButton2_Click">
                </dx:ASPxButton>
            </td>
        </tr>
    </table>
    <br />
    <dx:ASPxGridView ID="grd1" runat="server" AutoGenerateColumns="False" KeyFieldName="RequestId"
        OnCustomUnboundColumnData="grd1_CustomUnboundColumnData" OnHtmlDataCellPrepared="grd1_HtmlDataCellPrepared"
        KeyboardSupport="True" OnCustomColumnDisplayText="grd1_CustomColumnDisplayText">
        <Columns>
            <dx:GridViewDataHyperLinkColumn Caption="№" FieldName="RequestId" ReadOnly="True" VisibleIndex="0" Width="60px" Name="ID">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/So/rqdetail.aspx?code={0}" TextField="RequestId" Target="_self">
                </PropertiesHyperLinkEdit>
                <EditFormSettings Visible="False" />
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataTextColumn Caption="ДУ" FieldName="DU" ReadOnly="True" VisibleIndex="1" Width="80px">
                <PropertiesTextEdit DisplayFormatString="{0}">
                </PropertiesTextEdit>
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Added" Caption="Добавлена" VisibleIndex="2" ReadOnly="True" Width="140px">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="WorkType" Caption="Вид работ" VisibleIndex="3" ReadOnly="True" Width="120px">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Addr" Caption="Адрес" VisibleIndex="4" ReadOnly="True" Width="160px">
                <Settings AutoFilterCondition="Contains" />
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="LocationTitle" Caption="Локализация" VisibleIndex="5" ReadOnly="True" Width="90px">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="State" Caption="Статус" VisibleIndex="6" ReadOnly="True" Width="140px">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="NOTE" Caption="Коментарий" VisibleIndex="7" ReadOnly="True">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Price" Caption="Цена" VisibleIndex="8" Width="60px">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Status" VisibleIndex="9" Visible="false">
            </dx:GridViewDataTextColumn>
        </Columns>
        <SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True" ColumnResizeMode="Control" EnableCustomizationWindow="True" AllowSelectSingleRowOnly="True" />
        <Settings ShowFilterBar="Auto" ShowFilterRow="True" ShowFooter="True" ShowFilterRowMenu="True" ShowFilterRowMenuLikeItem="True" />
        <SettingsPager PageSize="10">
            <PageSizeItemSettings Visible="True">
            </PageSizeItemSettings>
        </SettingsPager>
        <Paddings PaddingLeft="10px" PaddingRight="10px" />
        <Styles>
            <Header HorizontalAlign="Left" VerticalAlign="Middle" Wrap="True">
            </Header>
        </Styles>
    </dx:ASPxGridView>
    <asp:SqlDataSource ID="ds_request" runat="server" ConnectionString="<%$ ConnectionStrings:DispatcherWebAppConnectionString %>" SelectCommand="SELECT rq.RequestId, _house_company.Title + '`' + CAST(rq.LocalId AS varchar) AS DU, CONVERT (varchar, dbo.GetLocalData(rq.CreatedAtUtc), 104) + ' ' + CONVERT (varchar, dbo.GetLocalData(rq.CreatedAtUtc), 108) + '`' + _created_by.LastName + ' ' + LEFT (_created_by.FirstName, 1) + '.' + LEFT (_created_by.MiddleName, 1) + '.' + '`' + _created_by_company.Title + '`' + CONVERT (varchar, dbo.GetLocalData(rq.IssuedAtUtc), 104) + ' ' + CONVERT (varchar, dbo.GetLocalData(rq.IssuedAtUtc), 108) AS Added, _job_type.Title + '`' + _job_subtype.Title AS WorkType, _street.Title + CASE WHEN _house.Title IS NULL THEN '' ELSE ', ' + _house.Title END + CASE WHEN rq.Apartment IS NULL THEN '' ELSE N', кв. ' + CAST(rq.Apartment AS VARCHAR) END + CASE WHEN rq.Entrance IS NULL THEN '' ELSE ', ' + CAST(rq.Entrance AS VARCHAR) + N' подъезд' END + CASE WHEN rq.[Floor] IS NULL THEN '' ELSE ', ' + N' этаж ' + CAST(rq.[Floor] AS VARCHAR) END + CASE WHEN rq.AccessCode IS NULL THEN '' ELSE ', ' + N' домофон: ' + CAST(rq.AccessCode AS VARCHAR) END + CASE WHEN rq.RequesterPhone = '' THEN '' ELSE ', ' + N' тел.: ' + CAST(rq.RequesterPhone AS VARCHAR) END AS Addr, CASE WHEN rq.Location = 1 THEN N'Дом' WHEN rq.Location = 2 THEN N'Квартира' WHEN rq.Location = 3 THEN N'Подъезд' WHEN rq.Location = 4 THEN N'Лестничная клетка' WHEN rq.Location = 5 THEN N'Крыша' WHEN rq.Location = 6 THEN N'Другое' WHEN rq.Location = 7 THEN N'Подвал' WHEN rq.Location = 8 THEN N'Мусоропровод' WHEN rq.Location = 9 THEN N'Территория' WHEN rq.Location = 10 THEN N'Карман' ELSE '' END AS LocationTitle, CASE WHEN rq.[Status] = 1 THEN N'Не рассмотрена' WHEN rq.[Status] = 2 THEN N'В процессе' WHEN rq.[Status] = 3 THEN N'Выполнена' WHEN rq.[Status] = 4 THEN N'Возвращена' WHEN rq.[Status] = 5 THEN N'Снята' WHEN rq.[Status] = 6 THEN N'Закрыта' WHEN rq.[Status] = 7 THEN N'Отложена' WHEN rq.[Status] = 8 THEN N'Текущий ремонт' WHEN rq.[Status] = 9 THEN N'Запрос в службу эксплуатации (СЭ)' ELSE '' END + '`' + _house_company.Title + CASE WHEN rq.CompletedAtUtc IS NULL THEN '' ELSE '`' + N'Факт. выполнена:' + '`' + CONVERT (varchar , dbo.GetLocalData(rq.CompletedAtUtc) , 104) + ' ' + CONVERT (varchar , dbo.GetLocalData(rq.CompletedAtUtc) , 108) END AS State, rq.RequestBody + '`' + '^' + '`' + _last_key_comment.CommentBody AS NOTE, rq.Price, rq.Status FROM Rq_Request AS rq INNER JOIN App_Company AS _mgmt_company ON _mgmt_company.CompanyId = rq.MgmtCompanyId INNER JOIN App_Company AS _house_company ON _house_company.CompanyId = rq.HouseCompanyId INNER JOIN App_User AS _created_by ON _created_by.UserId = rq.CreatedBy INNER JOIN App_Company AS _created_by_company ON _created_by_company.CompanyId = _created_by.CompanyId INNER JOIN Rq_JobType AS _job_type ON _job_type.JobTypeId = rq.JobTypeId LEFT OUTER JOIN Rq_JobSubtype AS _job_subtype ON _job_subtype.JobSubtypeId = rq.JobSubtypeId INNER JOIN Geo_House AS _house ON _house.HouseId = rq.HouseId INNER JOIN Geo_Street AS _street ON _street.StreetId = _house.StreetId LEFT OUTER JOIN Rq_Comment AS _last_key_comment ON _last_key_comment.CommentId = rq.LastKeyCommentId WHERE (rq.IssuedAtUtc BETWEEN @d1 AND @d2)">
        <SelectParameters>
            <asp:SessionParameter Name="d1" SessionField="dt1" Type="DateTime" />
            <asp:SessionParameter Name="d2" SessionField="dt2" Type="DateTime" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:EntityDataSource ID="ds_company" runat="server" ConnectionString="name=DispatcherWebAppEntities" DefaultContainerName="DispatcherWebAppEntities" EnableFlattening="False" EntitySetName="App_Company" Select="it.[CompanyId], it.[Title], it.[MgmtCompanyId]">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="ds_JobType" runat="server" ConnectionString="name=DispatcherWebAppEntities" DefaultContainerName="DispatcherWebAppEntities" EnableFlattening="False" EntitySetName="Rq_JobType">
    </asp:EntityDataSource>
    <asp:SqlDataSource ID="ds_user" runat="server" ConnectionString="<%$ ConnectionStrings:DispatcherWebAppConnectionString %>" EnableCaching="True" SelectCommand="SELECT UserId, LastName + '.' + LEFT (FirstName, 1) + '.' + LEFT (MiddleName, 1) + '.' AS NAME FROM App_User"></asp:SqlDataSource>
    <asp:SqlDataSource ID="ds_JobSubtype" runat="server" ConnectionString="<%$ ConnectionStrings:DispatcherWebAppConnectionString %>" SelectCommand="SELECT [JobSubtypeId], [JobTypeId], [Title] FROM [Rq_JobSubtype] WHERE (([JobTypeId] = @JobTypeId) AND ([IsDeleted] = @IsDeleted))">
        <SelectParameters>
            <asp:Parameter DefaultValue="-1" Name="JobTypeId" Type="Int16" />
            <asp:Parameter DefaultValue="0" Name="IsDeleted" Type="Int16" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:EntityDataSource ID="ds_street" runat="server" ConnectionString="name=DispatcherWebAppEntities" DefaultContainerName="DispatcherWebAppEntities" EnableFlattening="False" EntitySetName="Geo_Street" EntityTypeFilter="Geo_Street">
    </asp:EntityDataSource>
    <asp:SqlDataSource ID="ds_house" runat="server" ConnectionString="<%$ ConnectionStrings:DispatcherWebAppConnectionString %>" SelectCommand="SELECT [HouseId], [Title] FROM [Geo_House] WHERE ([StreetId] = @StreetId)" EnableCaching="True">
        <SelectParameters>
            <asp:Parameter DefaultValue="-1" Name="StreetId" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <dx:ASPxLoadingPanel ID="ldpanel" runat="server" ClientInstanceName="ldpanel" Modal="True">
    </dx:ASPxLoadingPanel>
    <br />
</asp:Content>

